package cn.itsource.campus.util;

public class AjaxResult<T> {
    private Boolean success;

    private Integer code;

    private String message;
    private T  data;

    public AjaxResult() {
    }
    public AjaxResult(Boolean success, Integer code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static AjaxResult ok(){
        return new AjaxResult(true, 200, "", null);
    }

    public static AjaxResult ok(Object data){
        return new AjaxResult(true, 200, null, data);
    }
    public static AjaxResult ok(String message){
        return new AjaxResult(true, 200, message, null);
    }

    public static <T> AjaxResult ok(String message,T data){
        return new AjaxResult(true, 200, message, data);
    }

    public static AjaxResult fail(){
        return new AjaxResult(false, 500, "", null);
    }

    public static AjaxResult fail(Integer code){
        return new AjaxResult(false, code, "", null);
    }
    public static AjaxResult fail(Integer code,String message){
        return new AjaxResult(false, code, message, null);
    }

    public static AjaxResult fail(String message){
        return new AjaxResult(false, 500, message, null);
    }
    public static <T> AjaxResult fail(String message,T data){
        return new AjaxResult(false, 500, message, data);
    }
    public static <T> AjaxResult fail(Integer code,String message,T data){
        return new AjaxResult(false, code, message, data);
    }
    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
